<html>
<head>
	<title>测试sse</title>
	<script src="https://cdn.staticfile.org/crypto-js/4.0.0/crypto-js.min.js" type="text/javascript"></script>
	<script>
		// source = new EventSource("http://i9scm.me/adminscm/UserNotice/getInternalMsg?Usrid=912&SleepTime=5");
		// source.onmessage = function (event) {
		// 	json = JSON.parse(event.data);
		// 	console.log(json);
		// };


        /**
         * @description  加密函数,用于调用api之前
         * @param {Object} data data
         * @param {String} keyStr key值
         * @param {String} token
         */
        function encrypt(data, keyStr, token) { // 加密
            const key = CryptoJS.enc.Utf8.parse(keyStr);
            const encrypted = CryptoJS.AES.encrypt(data, key, {
                mode: CryptoJS.mode.CBC,
                padding: CryptoJS.pad.Pkcs7,
                iv: key	// 不建议这么写
            });
            return encrypted.ciphertext.toString(CryptoJS.enc.Hex);
        }



        /**
         * @description  解密函数,用于调用api之后
         * @param {Object}  axios_data data
         * @param keyStr
         */
        function decrypt(data, keyStr = '5358468425923574') { // 解密
                                                              // console.log(keyStr)
                                                              // console.log(data)
            const key = CryptoJS.enc.Utf8.parse(keyStr);
            var encryptedHexStr = CryptoJS.enc.Hex.parse(data);
            var srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
            // console.log(keyStr, srcs)
            const decrypt = CryptoJS.AES.decrypt(srcs, key, {
                mode: CryptoJS.mode.CBC,
                padding: CryptoJS.pad.Pkcs7,
                iv: key	// 不建议这么写
            });
            var decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
            return decryptedStr.toString();
        }

        // var data = '{"store_id":"823"}';
        // var key =  "kl34aj7812if5678";
        // var aa = encrypt(data, key, '');
        // console.log(aa);

        // aa = 'ccc3c9fabedfab1a3707dd3243037e0d8dfa9b23efbf7d25e73a9e59c5f8314c';
        aa = '4b980f1bbf0c6d708df7f4320ec1b78eeb39b85d8bb0a0d7f2aaa963a2229bc120085a13b25b1c0da44d99f33300db88';
        key = 'kl34aj7812if5678';
        var bb = decrypt(aa, key);
        console.log(bb);



	</script>
</head>
<body>
<div>123456</div>
</body>
</html>